<?php

echo "Process start time".date('Y-m-d H:i:s').PHP_EOL;
$urls = [
    'http://baidu.com',
    'http://sina.com.cn',
    'http://qq.com',
    'http://baidu.com?search=singwa',
    'http://baidu.com?search=singwa2',
    'http://baidu.com?search=imooc',
];
$workers = [];
for($i = 0; $i < 6;$i++){
   $process = new swoole_process(function($pro) use($i,$urls){
        echo "Start the child Process".$urls[$i].PHP_EOL;
       $res = curlData($urls[$i]);
       //writing the data into the pipe
       $pro->write($res);
    },true);
   $pid = $process->start();
   $workers[$pid] = $process;

}

foreach($workers as $process){
    // reading the data from the pipe
   echo  $process->read();
}
echo "Process end time".date('Y-m-d H:i:s').PHP_EOL;

function curlData($url){
    sleep(1);
    return $url."success".PHP_EOL;
}